package com.guhecloud.step.definition.runtime.def;

import com.guhecloud.step.definition.runtime.*;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

@Getter
public class PolicyDef implements IRegistryAware {
    private Class<? extends IDomainExtension> extClazz;
    private IExtPolicy policyBean;

    private Map<String, ExtensionDef> extensionDefMap = new HashMap<>();

    @Override
    public void registerBean(Object bean) {
        InternalIndexer.index(this);
    }

    public ExtensionDef getExtension(IDomainModel model) {
        final String extensionCode = policyBean.extensionCode(model);
        if (extensionCode == null) {
            return null;
        }

        return extensionDefMap.get(extensionCode);
    }

    public void registerExtensionDef(ExtensionDef extensionDef) {
        extensionDefMap.put(extensionDef.getCode(), extensionDef);
    }
}
